﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;

namespace BLLTarasca
{
    public class Mailer
    {
        public void EnviarEmail(string emailDestino, string asunto, string html, Dictionary<string, string> variables)
        {
            foreach (KeyValuePair<string,string> item in variables)
                html = html.Replace(item.Key, item.Value);

            MailMessage mensaje = new MailMessage();
            mensaje.Body = html;
            mensaje.Subject = asunto;

            AlternateView vistaHtml = AlternateView.CreateAlternateViewFromString(html, new ContentType("text/HTML"));
            mensaje.AlternateViews.Add(vistaHtml);

            mensaje.To.Add(new MailAddress(emailDestino));

            SmtpClient client = new SmtpClient();
            client.Send(mensaje);
        }
    }
}
